//
//  SourceListCell.m
//  HuoFeiDaShipper
//
//  Created by mac on 2019/11/13.
//  Copyright © 2019 zhuchongjin. All rights reserved.
//

#import "SourceListCell.h"

@interface SourceListCell()
@property (strong, nonatomic) CJLabel *labOrderNum;
@property (strong, nonatomic) CJLabel *labOrderStatue;
@property (strong, nonatomic) CJLabel *labShipperAdress;
@property (strong, nonatomic) CJLabel *labConsigneeAdress;

@property (strong, nonatomic) FlexTouchView *viewDetail; // 系=详情
@property (nonatomic,strong) FlexTouchView *viewAgain; // 再来一单
@property (strong, nonatomic) FlexTouchView *viewStop; //
@property (nonatomic,strong) FlexTouchView *viewRefresh; // 刷新
@property (nonatomic,strong) FlexTouchView *viewPrice; // 竞价
@property (nonatomic,strong) FlexTouchView *viewFinishOrder; //结束货源
@property (strong, nonatomic) FlexTouchView *viewDelecte; //
@property (strong, nonatomic) FlexTouchView *QRCodeView;//二维码
@property (strong, nonatomic) FlexTouchView *QRCodeView1;
//@property (nonatomic,strong) UIView *viewSendOrder;
//@property (nonatomic,strong) UIView *viewPush;
@property (strong, nonatomic) FlexTouchView *viewChange; //
@property (nonatomic,strong) FlexTouchView *viewAdjustPrice; //调价
@property (nonatomic,strong) FlexTouchView *changeXHAddress; //修改卸货地
@property (nonatomic,strong) CJLabel *labBidCount;

@property (nonatomic,strong) CJLabel *labCoalTypeName;
@property (nonatomic,strong) CJLabel *labCoalPrice;
@property (nonatomic,strong) CJLabel *labPushVehicleUse;

@property (nonatomic,strong) CJView *viewBottomLine;
@property (nonatomic,strong) CJView *viewTopLine;

@property (nonatomic,strong) FlexScrollView *scrollView;
@property (nonatomic,strong) UIView *viewBottom;

@property (strong, nonatomic) FlexTouchView *viewDetail1; // 系=详情
@property (nonatomic,strong) FlexTouchView *viewAgain1; // 再来一单
@property (strong, nonatomic) FlexTouchView *viewStop1; //
@property (nonatomic,strong) FlexTouchView *viewRefresh1; // 刷新
@property (nonatomic,strong) FlexTouchView *viewPrice1; // 竞价
@property (nonatomic,strong) FlexTouchView *viewFinishOrder1; //结束货源
@property (strong, nonatomic) FlexTouchView *viewDelecte1; //
//@property (nonatomic,strong) UIView *viewSendOrder;
//@property (nonatomic,strong) UIView *viewPush;
@property (strong, nonatomic) FlexTouchView *viewChange1; //
@property (nonatomic,strong) FlexTouchView *viewAdjustPrice1; //调价
@property (nonatomic,strong) CJLabel *labBidCount1;

@property (nonatomic,strong) UIView *viewBG;


@end

@implementation SourceListCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)setCellInfoWithSourceModel:(SourceListModel *)model{
    
//    self.labOrderNum.text = CJStringWithFormat(@"货源单号:%@",model.mainOrderNumber);
    self.labOrderNum.text = model.mainOrderNumber;
//    self.labOrderStatue.text = @"状态啊";
    self.labOrderStatue.textColor = [UIColor cjMainTextColor];
//    self.titleArray = @[@"全部",@"未接单",@"已接单",@"已装货",@"已卸货",@"已核算",@"已完成",@"已撤销",@"常发货源"];
//     self.titles = @[@"0",@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8"];
//    [self.viewBG showBadgeWithStyle:WBadgeStyleRedDot value:0 animationType:WBadgeAnimTypeNone];
    if (model.isCancel == 0) {
        
        switch (model.status) {
            case 0:
                self.labOrderStatue.text = @"未接单";
                break;
            case 1:
                self.labOrderStatue.text = @"已接单";
                break;
            case 2:
                self.labOrderStatue.text = @"已装货";
                break;
            case 3:
                self.labOrderStatue.text = @"已卸货";
                break;
            case 4:
                self.labOrderStatue.text = @"已核算";
                break;
            case 5:
                self.labOrderStatue.text = @"已完成";
                break;

            default:
                break;
        }
    }else{
        self.labOrderStatue.text = @"已撤销";
    }
    if (model.isQuote == 3) {
        self.labOrderStatue.text = @"固定项目单";
    }
//    if (model.isOftenOrder == 1 && model.isCancel == 0) {
//        self.labOrderStatue.text = @"常发货源";
//    }
    
    // zhuanghuo  卸货
    self.labShipperAdress.text = CJStringWithFormat(@"%@%@",model.shipperAddress,model.shipperDetailAddress);
    self.labConsigneeAdress.text = CJStringWithFormat(@"%@%@",model.consigneeAddress,model.consigneeDetailAddress);
//     竞价
    if (model.bidCount == 0) {
        self.labBidCount.text = @"竞价";
    }else{
        self.labBidCount.text = CJStringWithFormat(@"竞价(%ld)",(long)model.bidCount);
    }
    
//    self.labBidCount.text = [CJControl getThreeUnaryValueStr:model.bidCount] ? @"竞价":CJStringWithFormat(@"竞价(%@)",model.bidCount);
//    self.labCoalTypeName.text = model.coalTypeName;
//    self.labCoalPrice.text = CJStringWithFormat(@"%ld %@",(long)model.coalPrice ,model.isTrunkName);
//    self.labPushVehicleUse.text = model.pushVehicleUse;
    
//    self.labCoalTypeName.text = CJStringWithFormat(@"%@ %@%@ %@%@ %@",[CJRegular getIsStrEmpty:model.coalTypeName] ? @"":model.coalTypeName,model.coalPrice ,[CJRegular getIsStrEmpty:model.isTrunkName] ? @"":model.isTrunkName, model.weight ,[CJRegular getIsStrEmpty:model.coalUnitName] ? @"":model.coalUnitName ,[CJRegular getIsStrEmpty:model.pushVehicleUse] ? @"":model.pushVehicleUse);
    if (model.isTrunk == 3) {
        self.labCoalTypeName.text = CJStringWithFormat(@"%@ %@%@ %@元/%@ %@",[CJRegular getIsStrEmpty:model.coalTypeName] ? @"":model.coalTypeName,@(model.weight).cj_description ,[CJRegular getIsStrEmpty:model.coalUnitName] ? @"":model.coalUnitName, @(model.coalPrice).cj_money_description ,[CJRegular getIsStrEmpty:model.coalUnitName] ? @"车":model.coalUnitName ,[CJRegular getIsStrEmpty:model.pushVehicleUse] ? @"":model.pushVehicleUse);
    }else{
        self.labCoalTypeName.text = CJStringWithFormat(@"%@ %@%@ %@元/%@ %@",[CJRegular getIsStrEmpty:model.coalTypeName] ? @"":model.coalTypeName,@(model.weight).cj_description ,[CJRegular getIsStrEmpty:model.coalUnitName] ? @"":model.coalUnitName, @(model.coalPrice).cj_money_description ,[CJRegular getIsStrEmpty:model.coalUnitName] ? @"":model.coalUnitName ,[CJRegular getIsStrEmpty:model.pushVehicleUse] ? @"":model.pushVehicleUse);
    }
    
    // 处理按钮逻辑
    // 详情
    self.viewDetail.hidden = NO;
    self.changeXHAddress.hidden = NO;
    // 在来一单
    self.viewAgain.hidden = NO;
    //修改
    self.viewChange.hidden = model.isCancel == 0 && model.status == 0 && model.isFinishOrder == 0 ? NO:YES;
    //二维码接单
//    self.QRCodeView.hidden = model.isCancel == 0 && model.status == 0 && model.isFinishOrder == 0 ? NO:YES;
    self.QRCodeView.hidden = NO;
    //zanting
    self.viewStop.hidden = model.isCancel == 0 && model.isFinishOrder == 0 ? NO:YES;
    
    self.viewRefresh.hidden = model.isCancel == 1 && model.isFinishOrder == 0 ? NO:YES;
    
    self.viewPrice.hidden = model.isCancel == 0 && model.isQuote == 1 && model.bidCount > 0 ? NO:YES;
//    self.viewRefresh.hidden = model.isCancel == 0 && model.isQuote == 1 && model.bid
    self.viewDelecte.hidden = model.status == 0 ? NO:YES;
//    self.viewSendOrder.hidden = model.isCancel == 0 && model.lastWeight > 0 &&((model.coalNumber > 0 && model.notReceivedCount > 0) || model.notReceivedCount == 0) ? NO:YES;
//    self.viewPush.hidden = model.isCancel == 0 && model.lastWeight > 0 &&((model.coalNumber > 0 && model.notReceivedCount > 0) || model.notReceivedCount == 0) ? NO:YES;
    
    self.viewAdjustPrice.hidden = model.isCancel == 0 && model.isFinishOrder == 0 ? NO:YES;
    
  // 结束货源
    if (model.isFinishOrder == 0) {
        self.viewFinishOrder.hidden = NO;
    }else{
        self.viewFinishOrder.hidden = YES;
    }
    //     竞价
    if (model.bidCount == 0) {
        self.labBidCount1.text = @"竞价";
    }else{
        self.labBidCount1.text = CJStringWithFormat(@"竞价(%ld)",(long)model.bidCount);
    }

    // 处理按钮逻辑

    // 详情
    self.viewDetail1.hidden = NO;
    self.changeXHAddress.hidden = NO;
    // 在来一单
    self.viewAgain1.hidden = NO;
    //修改
    self.viewChange1.hidden = model.isCancel == 0 && model.status == 0 && model.isFinishOrder == 0 ? NO:YES;
    //二维码派单
    self.QRCodeView1.hidden =  NO;
    //zanting
    //        self.viewStop1.hidden = model.isCancel == 0 && model.lastWeight > 0 &&((model.coalNumber > 0 && model.notReceivedCount > 0) || model.notReceivedCount > 0) ? NO:YES;
    self.viewStop1.hidden = model.isCancel == 0 && model.isFinishOrder == 0 ? NO:YES;
    self.viewRefresh1.hidden = model.isCancel == 1 &&model.isFinishOrder==0? NO:YES;
    //
    self.viewPrice1.hidden = model.isCancel == 0 && model.isQuote == 1 && model.bidCount > 0 ? NO:YES;
    //    self.viewRefresh.hidden = model.isCancel == 0 && model.isQuote == 1 && model.bid
    self.viewDelecte1.hidden = model.status == 0 ? NO:YES;
    //    self.viewSendOrder.hidden = model.isCancel == 0 && model.lastWeight > 0 &&((model.coalNumber > 0 && model.notReceivedCount > 0) || model.notReceivedCount == 0) ? NO:YES;
    //    self.viewPush.hidden = model.isCancel == 0 && model.lastWeight > 0 &&((model.coalNumber > 0 && model.notReceivedCount > 0) || model.notReceivedCount == 0) ? NO:YES;
    self.viewAdjustPrice1.hidden = model.isCancel == 0 && model.isFinishOrder == 0 ? NO:YES;

    // 结束货源
    if (model.isFinishOrder == 0) {
        self.viewFinishOrder1.hidden = NO;
    }else{
        self.viewFinishOrder1.hidden = YES;
    }

    int  i = 0;
    // 显示加一
    if (self.viewDetail.hidden == NO) {
        i++;
    }
    if (self.changeXHAddress.hidden == NO) {
        i++;
    }
    if (self.viewAgain.hidden == NO) {
        i++;
    }
    if (self.viewChange.hidden == NO) {
        i++;
    }
    if (self.QRCodeView.hidden == NO) {
        i++;
    }
    if (self.viewStop.hidden == NO) {
        i++;
    }
    if (self.viewRefresh.hidden == NO) {
        i++;
    }
    if (self.viewPrice.hidden == NO) {
        i++;
    }
    if (self.viewDelecte.hidden == NO) {
        i++;
    }
    if (self.viewAdjustPrice.hidden == NO) {
        i++;
    }
//    if (model.isOftenOrder == 0) {
//        i++;
//    }
    if (i > 3) {
        self.scrollView.hidden = NO;
        self.viewBottom.hidden = YES;
    }else{
        self.scrollView.hidden = YES;
        self.viewBottom.hidden = NO;
    }
}

- (void)orderDetailBtn{
    
    if (self.blockDetail) {
        self.blockDetail(@"");
    }
}

- (void)QRCodeViewAgainAction{
    if(self.QRCodeDelegate){
        self.QRCodeDelegate(@"");
    }
}

- (void)btnOrderAgainAction{
    if (self.blcokAgain) {
        self.blcokAgain(@"");
    }
}

- (void)btnClickChangeAction{
    if (self.blockChange) {
        self.blockChange(@"");
    }
}

- (void)btnClickStopAction{
    
    if (self.blockStop) {
        self.blockStop(@"");
    }
}

- (void)btnClickRefreshAction{
    if (self.blcokRefresh) {
        self.blcokRefresh(@"");
    }
}

- (void)btnMakePriceAction{
    if (self.blcokPrice) {
        self.blcokPrice(@"");
    }
}

- (void)btnFinishOrderAction{
    if (self.blockFinish) {
        self.blockFinish(@"");
    }
}

//- (void)btnSenderOrderAction{
//    if (self.blcokSendOrders) {
//        self.blcokSendOrders(@"");
//    }
//}

- (void)btnClicksDelecteAction{
    if (self.blockDelecte) {
        self.blockDelecte(@"");
    }
}

//- (void)btnPushOrderAction{
//    if (self.blockPush) {
//        self.blockPush(@"");
//    }
//}

- (void)btnAdjustPriceAction{
//    [CJAlert showStringDismissWithDelay:@"隐私协议"];
    if (self.blockAdjustPrice) {
        self.blockAdjustPrice(@"");
    }
}

- (void)changeAddressAction{
    if (self.blockChangeAddress) {
        self.blockChangeAddress(@"");
    }
}

//- (void)btnBiddingPriceAction{
//    if (self.blockBiddingPrice) {
//        self.blockBiddingPrice(@"");
//    }
//}
- (void)drawRect:(CGRect)rect{
    [CJControl drawLineOfDashByCAShapeLayer:self.viewBottomLine lineLength:2 lineSpacing:1.5 lineColor:[UIColor cjBackgroundColor] lineDirection:NO];
    [CJControl drawLineOfDashByCAShapeLayer:self.viewTopLine lineLength:2 lineSpacing:1.5 lineColor:[UIColor cjBackgroundColor] lineDirection:NO];
}

@end

